"""
@version:
@filename : 三乐购物系统
@author : liuhongjie
@projectname: day02
@time: 2022/06/12
"""

class User:
    def __init__(self,name,passwd,money):
        self.name = name
        self.passwd = passwd
        self.money = money
    def buy_goods(self,good,weight):
        if weight>good.store:
            print("库存不足！")
        else:
            pay = weight*good.price
            if self.money>=pay:
                self.money-=pay
                good.store-=weight
                print(f"购买成功，{self.name}剩余{self.money}元，"
                      f"{good.product_name}剩余库存{good.store}")
            else:
                print("余额不足！")
    def goods_info(goods):
        goodsinfo = []
        goodsinfo.append(goods)
        print(goodsinfo)

class Goods:
    def __init__(self,classify,product_name,price,store):
        self.classify = classify
        self.product_name = product_name
        self.price = price
        self.store = store
apple = Goods("fruits", "apple", 8, 30)
orange = Goods("fruits", "orange", 4, 100)

class login:
    def __init__(self,username,passwd):
        self.username = username
        self.passwd = passwd
class regist:
    def __init__(self,username,passwd,money):
        self.username = username
        self.passwd = passwd
        self.money = money

while 1:
        print("欢迎来到三乐商店")
        select = input("选择登录、注册、退出：\n")
        if select == "注册":
            newname = input("请输入你的姓名：")
            newpasswd = input("请输入你的密码：")
            newmoney = int(input("请输入你要存的钱："))
            user1 = User(newname, newpasswd, newmoney)
            regist1 = regist(newname, newpasswd, newmoney)
            print("注册成功返回首页登录")
            continue

        elif select == "登录":
            name = input("please input name:")
            passwd = input("please input passwd:")
            if regist1.username==name and regist1.passwd==passwd:
                print("登录成功")
            while True:
                select2 = input("1、按q退出：\n"
                              "2、选择购物：\n"
                              "3、查询购物信息：\n")
                if select2.upper()=="Q":
                    break
                elif select2 =="2":
                    goods = input("请输入商品名称:")
                    weight1 = int(input("请输入重量(kg):"))
                    user1.buy_goods(apple,weight1)
                elif select2 == "3":
                    pass
                else:
                    print("你输入的有误，请重新输入")
        elif select == "退出":
                break

